package com.xcity.pomelo.response;

import java.util.ArrayList;
import java.util.List;

import com.xcity.db.entity.Player;
import com.xcity.game.recharge.RechargeTemplate;

import naga.x.App;
import naga.x.game.template.TemplateService;
import naga.x.net.impl.pomelo.PomeloMessage;
import naga.x.net.impl.pomelo.protocol.Message;

@PomeloMessage(type = Message.Type.RESPONSE)
public class RechargeRewardListResponse extends Response {

	private List<RechargeInfo> list;
	
	public static class RechargeInfo{
		public int type;
		public int id;
		public int needMoney;
		public int state;
		public RechargeInfo(int type, RechargeTemplate temp, int state){
			this.type = type;
			this.id = temp.getId();
			this.needMoney = temp.getPrice();
			this.state = state;
		}
	}
	public RechargeRewardListResponse(int serial, int stateData, int[] rewards, int[] rechargeIds) {
		super(serial);
		
		int size = rewards.length;
		if(size > rechargeIds.length){
			size = rechargeIds.length;
		}
		list = new ArrayList<RechargeInfo>();
		TemplateService ts = App.getApp().getServiceManager().get(TemplateService.class);
		for(int i = 0; i < size; i++){
			RechargeTemplate rt = ts.get(RechargeTemplate.class, rechargeIds[i]);
			if(rt != null){
				int got = (stateData >> (i << 1)) & 0x3;
				RechargeInfo info = new RechargeInfo(i, rt, got);
				list.add(info);
			}
		}
	}
	public List<RechargeInfo> getList() {
		return list;
	}
	public void setList(List<RechargeInfo> list) {
		this.list = list;
	}
}
